package cn.itcast.es.controller;

import cn.itcast.es.pojo.ESDemoBean;
import cn.itcast.es.service.IESDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by bothin
 * At 2020/4/2 10:55
 * Description:
 */
@RestController
@RequestMapping("/demo")
public class ESDemoController {

    @Autowired
    private IESDemoService service;

    @GetMapping("/init")
    public void init(){
        service.createIndex();
        List<ESDemoBean> list =new ArrayList<>();
        list.add(new ESDemoBean(1L,"XX0193","XX8064","xxx11xxx",1));
        list.add(new ESDemoBean(2L,"XX0210","XX7475","xxx22xxxxxxx",1));
        list.add(new ESDemoBean(3L,"XX0257","XX8097","xxx33xxxxxxxxxxxxxxx",1));
        service.saveAll(list);

    }

    @GetMapping("/all")
    public Iterator<ESDemoBean> all(){
        return service.findAll();
    }
    
}
